package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.DestinationThemeRegion;
import cn.wolfcode.luowowo.article.mapper.DestinationMapper;
import cn.wolfcode.luowowo.article.mapper.DestinationThemeRegionMapper;
import cn.wolfcode.luowowo.article.query.DestinationThemeRegionQuery;
import cn.wolfcode.luowowo.article.service.IDestinationThemeRegionService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: linzhongjian
 * @email 911976613@qq.com
 * @Date: 2019/9/27 10:12
 * <p>
 * 功能描述:当季推荐服务
 */
@Service
public class DestinationThemeRegionServiceImpl implements IDestinationThemeRegionService {

   @Autowired
    private DestinationMapper destinationMapper;
    @Autowired
    private DestinationThemeRegionMapper destinationThemeRegionMapper;

    public PageInfo query(DestinationThemeRegionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(destinationThemeRegionMapper.selectForList(qo));
    }

    public void saveOrUpdate(DestinationThemeRegion destinationThemeRegion) {
        if(destinationThemeRegion.getId() == null){
            destinationThemeRegionMapper.insert(destinationThemeRegion);
        }else{
            destinationThemeRegionMapper.updateByPrimaryKey(destinationThemeRegion);
        }
    }

    public List<DestinationThemeRegion> list() {
        return destinationThemeRegionMapper.selectAll();
    }

    public List<Destination> getDestByRegionId(Long rid) {
        DestinationThemeRegion region = destinationThemeRegionMapper.selectByPrimaryKey(rid);
        return destinationMapper.selectByRegionIds(region.getRefIds());
    }
}
